package org.ares.app.demo.actions;

import java.util.HashMap;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import org.ares.app.demo.daos.ParamDao;
import org.ares.app.demo.daos.UserDao;
import org.ares.app.demo.entities.SParam;
import org.ares.app.demo.entities.SUser;
import org.ares.app.demo.models.d;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BizSysAction {
    static final Logger log = LoggerFactory.getLogger(BizSysAction.class);
    @Resource
    UserDao userdao;
    @Resource
    ParamDao paramdao;
    @Resource
    SUser curLoginUser;

    public BizSysAction() {
    }

    @RequestMapping({"/accessDenied"})
    @ResponseBody
    public String deny() {
        return "sorry,invalid user";
    }

    @RequestMapping({"/userlogin"})
    public String login() {
        return "pages/login";
    }

    @RequestMapping({"/", "/index"})
    public String index(Model m) {
        m.addAttribute("curUser", this.curLoginUser.getUsername());
        return "pages/index";
    }

    @RequestMapping({"/userauth"})
    public String userauth(@RequestParam(value = "curpage",defaultValue = "0") Integer curpage, @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize, Model m) {
        HashMap var4 = new HashMap();
        var4.put("admin", "超级管理员");
        var4.put("adv_user", "一般管理员");
        var4.put("nor_user", "普通用户");
        PageRequest var5 = new PageRequest(curpage, pagesize);
        m.addAttribute("users", this.userdao.queryAll(var5));
        m.addAttribute("roles", var4);
        m.addAttribute("curUser", this.curLoginUser.getUsername());
        return "pages/userauth";
    }

    @RequestMapping({"/user/query_all"})
    public String user_query(Model m) {
        m.addAttribute("users", this.userdao.findAll());
        return "pages/userauth";
    }

    @RequestMapping({"/user/set_adv"})
    public String user_setadv(d m) {
        String var2 = m.a();
        if (!StringUtils.isEmpty(var2)) {
            this.userdao.setAdvUser(var2);
        }

        return "redirect:/userauth";
    }

    @RequestMapping({"/user/set_nor"})
    public String user_setnor(d m) {
        String var2 = m.a();
        if (!StringUtils.isEmpty(var2)) {
            this.userdao.setNorUser(var2);
        }

        return "redirect:/userauth";
    }

    @RequestMapping({"/user/disable"})
    public String user_dis(d m) {
        String var2 = m.a();
        if (!StringUtils.isEmpty(var2)) {
            this.userdao.disableUser(var2);
        }

        return "redirect:/userauth";
    }

    @RequestMapping({"/param/setip"})
    public String prm_setip(@NotNull String sand_ip) {
        SParam var2 = (SParam)this.paramdao.findOne("sand_ip");
        var2.setVal(sand_ip);
        this.paramdao.save(var2);
        return "redirect:/";
    }
}
